using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Threading;


namespace _3D_FileExplorer
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class DrawBoundingCubes : DrawableGameComponent
    {
        List<BoundingCube> cubeList = new List<BoundingCube>();
        CreateGraphicsTree cgt;
        BasicEffect effect;
        //BasicEffect effect;
        public DrawBoundingCubes(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
           
           
            base.Initialize();
            effect = new BasicEffect(GraphicsDevice, null);
            GraphicsDevice.VertexDeclaration =
           new VertexDeclaration(GraphicsDevice,
           VertexPositionColorTexture.VertexElements);
        }
        protected override void LoadContent()
        {
            cgt = new CreateGraphicsTree(@"C:\users/admin", Matrix.Identity, Matrix.Identity, 3);
            goTree(cgt.gTree);
            base.LoadContent();
        }
        void goTree(List<GraphicalNode> tree)
        {
            foreach (GraphicalNode pokus in tree)
            {
                if (pokus.Dir == true)
                {
                    cubeList.Add(new BoundingCube(pokus.BbParametersMinus.X, pokus.BbParametersPlus.X, pokus.BbParametersMinus.Y, pokus.BbParametersPlus.Y, pokus.BbParametersMinus.Z, pokus.BbParametersPlus.Z, pokus.translation, Color.Red));
                }
                else
                {
                    cubeList.Add(new BoundingCube(pokus.BbParametersMinus.X, pokus.BbParametersPlus.X, pokus.BbParametersMinus.Y, pokus.BbParametersPlus.Y, pokus.BbParametersMinus.Z, pokus.BbParametersPlus.Z, pokus.translation, Color.Blue));
                }
                if (pokus.Branch != null)
                {
                    goTree(pokus.Branch);
                }
            }
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }
        public override void Draw(GameTime gameTime)
        {
            
            foreach (BoundingCube bc in cubeList)
            {
                bc.Draw(effect, Fe.camera, ((Fe)Game).GraphicsDevice);
            }


            base.Draw(gameTime);
        }
    }
}